/**
 * 
 */
package com.suyx.job.utils.mh;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.suyx.job.utils.ImageUtils;
import com.suyx.job.utils.SampleOCRUtil;
import com.suyx.job.utils.ScreenCapture;

import lombok.extern.slf4j.Slf4j;

/**
 * @author syx
 *
 */
@Slf4j
@Component
public class StlScene {

	@Autowired
	private WaTuUtils waTuUtils;
	
	public final static Map<String,String> options_x = new HashMap<>();  
	public final static Map<String,String> options_y = new HashMap<>();
	static {  
		options_x.put("0", "701 327");  
		options_x.put("1", "408 226");  
		options_x.put("2", "508 226");
		options_x.put("3", "608 226"); 
		options_x.put("4", "408 326");
		options_x.put("5", "508 326");
		options_x.put("6", "608 326");
		options_x.put("7", "408 426");
		options_x.put("8", "508 426");
		options_x.put("9", "608 426");
		
		options_y.put("0", "830 320");  
		options_y.put("1", "539 225");  
		options_y.put("2", "639 225");
		options_y.put("3", "739 225"); 
		options_y.put("4", "539 325");
		options_y.put("5", "639 325");
		options_y.put("6", "739 325");
		options_y.put("7", "539 425");
		options_y.put("8", "639 425");
		options_y.put("9", "739 425");
	} 
	
	public  void stl(String device ,String zuobiao,String baoguo) throws Exception{
		//打开包裹
		ScreenCapture.mouseClick(device, "1308 675");
		ScreenCapture.mouseClick(device, "1000 224");// 打开zzg 7
		ScreenCapture.mouseClick(device, "522 422");// 使用
		ScreenCapture.mouseClick(device, "370 603");//7
		ScreenCapture.mouseClick(device, "1156 52");// 关闭包裹
		ScreenCapture.mouseClick(device, "74 668");// 出朱紫国到境外
		
		Thread.sleep(2 * 1000L);
		ScreenCapture.mouseClick(device, "80 687");// 从境外到stl
	}
	
	public  void stlSceneSame(String device,String zuobiao,String baoguo) throws Exception{
		Thread.sleep(5 * 1000L);
		ScreenCapture.mouseClick(device, "117 68");//打开地图
        ScreenCapture.mouseClick(device, "425 110");// 选x坐标
        String x = zuobiao.split(" ")[0];
        String y = zuobiao.split(" ")[1];
        input_x(device,x);
        ScreenCapture.mouseClick(device, "708 426");
        ScreenCapture.mouseClick(device, "561 104"); // 选y坐标
        input_y(device, y);
        ScreenCapture.mouseClick(device, "839 425");
        ScreenCapture.mouseClick(device, "704 109");  // 前往
        ScreenCapture.mouseClick(device, "1134 79"); //关闭地图
        //开始挖图
        waTuUtils.startWatu(device, zuobiao, baoguo);
	}
	
	private static void fen(String device,String baoguo,String zuobiao) throws Exception{
		ScreenCapture.mouseClick(device, "1308 675");//  # 打开包裹
		ScreenCapture.mouseClick(device, baoguo) ;//点击藏宝图包裹
		ScreenCapture.mouseClick(device, "522 422");//#使用
		ScreenCapture.mouseClick(device,"1156 52");//#关闭包裹
		
		ScreenCapture.snapshot(device,"H:\\android\\imges\\",device + "_" +zuobiao.replace(" ", "_") + ".png");
        ImageUtils.cutPNG(new FileInputStream("H:\\android\\imges\\"+device + "_" +zuobiao.replace(" ", "_")+".png"),
                new FileOutputStream("H:\\android\\imges\\tuaddr\\"+device + "_" +zuobiao.replace(" ", "_")+"_btAddr.png"), 813,493,139,46);
        String bgZuobiao1 = SampleOCRUtil.sampleBasic("H:\\android\\imges\\tuaddr\\"+device + "_" +zuobiao.replace(" ", "_")+"_btAddr.png");
        System.out.println("bgZuobiao1:"+bgZuobiao1);
        if(bgZuobiao1.indexOf("浪子") != -1){
			ScreenCapture.mouseClick(device, "1390 681");// #自动
			Thread.sleep(20 * 1000L);
			ScreenCapture.mouseClick(device, "1242 558");//  # 取消自动自动
		} 
	}
	public  void input_x(String device,String x){
		for(int i =0;i<x.length();i++){
			char c = x.charAt(i);
			String x_zb = options_x.get(String.valueOf(c));
			ScreenCapture.mouseClick(device, x_zb);
		}
	}
	
	public  void input_y(String device,String y){
		for(int i =0;i<y.length();i++){
			char c = y.charAt(i);
			String y_zb = options_y.get(String.valueOf(c));
			ScreenCapture.mouseClick(device, y_zb);
		}
	}
	
}
